﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

public class CrashEvent : MonoBehaviour
{
    public AudioSource[] ArrayAudioSource;
    public GameObject PrefabEffect;
    private UnityAction m_act;
    // Start is called before the first frame update
    void Start()
    {
        ArrayAudioSource = GetComponents<AudioSource>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void CrashHappened(Vector3 vecPoint)
    {
        if(m_act != null)
        {
            m_act.Invoke();
            int nIdx = Random.Range(0, ArrayAudioSource.Length);
            ArrayAudioSource[nIdx].Play();
            GameObject _objCar = Instantiate(PrefabEffect, vecPoint, Quaternion.identity);
        }
    }

    public void Registe(UnityAction _ac)
    {
        m_act += _ac;
    }
    public void Unregiste(UnityAction _ac)
    {
        m_act -= _ac;
    }
}
